<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\admin\model;

use think\Model;

class LinkModel extends Model
{
    public function adminList($filter){
        $where = [
            'a.site_id' => get_site_id(),
        ];

        if ( !empty($filter['type']) ){
            $where['type'] = $filter['type'];
        }

        $category = empty($filter['category']) ? 0 : intval($filter['category']);
        if ( !empty($category) ){
            $where['b.cat_id'] = ['eq', $category];
        }

        $keyword = empty($filter['keyword']) ? '' : $filter['keyword'];
        if (!empty($keyword)) {
            $where['a.name'] = ['like', "%$keyword%"];
        }

        $list = $this
             -> alias('a')
             -> field('a.*, b.cat_name')
             -> join('__LINK_CATEGORY__ b','a.cat_id = b.cat_id')
             -> where($where)
             -> order('id desc')
             -> paginate(10);

        return $list;
    }

}
